//
//  HomeViewController.m
//  何五路
//
//  Created by _ADY on 15/6/5.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "HomeViewController.h"
#import "SearchViewController.h"
#import "GoodsDetailsViewController.h"
#import "UIViewController+NJKFullScreenSupport.h"
#import "ADWebViewController.h"
#import "ADTableViewController.h"
#import "SearchShopViewController.h"
#import "KillListViewController.h"
#import "YyYViewController.h"
#import "LoginViewController.h"
@interface HomeViewController ()
//@property (nonatomic) NJKScrollFullScreen *scrollProxy;
@end

#define picTag 2000
#define aPicTag 10
#define cTag 3000
#define fTag 6000
#define adHight (self.view.bounds.size.width*379)/653
@implementation HomeViewController
@synthesize mTableView,homeArray,featuredArray,fListArray,AdBigArray,AdMinusArray,AdBrandArray,AdShopThemeArray,killArray;

#pragma mark - QRCodeReader Delegate Methods

#pragma mark -
#pragma mark NJKScrollFullScreenDelegate
//
//- (void)scrollFullScreen:(NJKScrollFullScreen *)proxy scrollViewDidScrollUp:(CGFloat)deltaY
//{
//    [self moveNavigtionBar:deltaY animated:YES];
//    [self moveToolbar:-deltaY animated:YES]; // move to revese direction
//}
//
//- (void)scrollFullScreen:(NJKScrollFullScreen *)proxy scrollViewDidScrollDown:(CGFloat)deltaY
//{
//    [self moveNavigtionBar:deltaY animated:YES];
//    [self moveToolbar:-deltaY animated:YES];
//}
//
//- (void)scrollFullScreenScrollViewDidEndDraggingScrollUp:(NJKScrollFullScreen *)proxy
//{
//    [self hideNavigationBar:YES];
//    [self hideToolbar:YES];
//}
//
//- (void)scrollFullScreenScrollViewDidEndDraggingScrollDown:(NJKScrollFullScreen *)proxy
//{
//    [self showNavigationBar:YES];
//    [self showToolbar:YES];
//}
//
//- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
//{
//    [_scrollProxy reset];
//    [self showNavigationBar:YES];
//    [self showToolbar:YES];
//}
//
//- (void)viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//    [_scrollProxy reset];
//    [self showNavigationBar:animated];
//    [self showToolbar:animated];
//}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
       
    }
    else
    {
        NSLog(@"前往");
    }
}

- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result
{
    [self dismissViewControllerAnimated:YES completion:^{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:result delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往", nil];
        [alert show];
    }];
}

- (void)readerDidCancel:(QRCodeReaderViewController *)reader
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

#pragma mark 扫一扫
-(void)leftAction
{
    if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
        static QRCodeReaderViewController *reader = nil;
        static dispatch_once_t onceToken;
        
        dispatch_once(&onceToken, ^{
            reader    = [QRCodeReaderViewController new];
            reader.modalPresentationStyle = UIModalPresentationFormSheet;
        });
        reader.delegate = self;
        
        [reader setCompletionWithBlock:^(NSString *resultAsString) {
        }];
        
        [self presentViewController:reader animated:YES completion:NULL];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错误提示" message:@"无法识别当前二维码！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }
}

#pragma mark 信息中心
-(void)rightAction
{
    BOOL aLogin = [[NSUserDefaults standardUserDefaults] boolForKey:@"isLoginKey"];
    if (!aLogin) {
        [self loginAction];
        return;
    }
    YyYViewController *details = [[YyYViewController alloc] init];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

-(void)loginAction
{
    LoginViewController *browser = [[LoginViewController alloc] init];
    browser.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:browser animated:YES];
}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    searchBar.showsCancelButton = YES;
   
    for (UIView *subView in [[searchBar.subviews objectAtIndex:0] subviews])
    {
        if([subView isKindOfClass:[UIButton class]]){
            [(UIButton*)subView setTitle:@"取消" forState:UIControlStateNormal];
        }
    }
    
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [self bInBction];
    searchBar.showsCancelButton = YES;
    return YES;
}

-(void)bInBction
{
    SearchShopViewController *details = [[SearchShopViewController alloc] init];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    searchBar.showsCancelButton = NO;
    return YES;
}

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0)
{
    return YES;
}

#pragma mark  UISearchBar 响应事件
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    searchBar.showsCancelButton = NO;
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    [searchBar resignFirstResponder];
    searchBar.showsCancelButton = NO;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"首页";
        self.view.backgroundColor = bgColor;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:248/255.0 green:181/255.0 blue:0/255.0 alpha:1];
    self.navigationController.navigationBar.alpha = 1;
    
    if (killArray != nil)
    {
        [killArray removeAllObjects];
        
        NSMutableDictionary *postDic4 = [[NSMutableDictionary alloc] init];
        [postDic4 setObject:@"AppHomeActPanicBuy" forKey:@"code"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService HomepageSecKill:postDic4];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                {
//                     NSLog(@"秒杀场次列表 %@",myArray);
                    if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Entity"]] isEqualToString:@"<null>"])
                    {
                        for (NSDictionary *pic in [myArray objectForKey:@"Entity"])
                        {
                            [killArray addObject:pic];
                        }
                    }
                }
                if (msLabel != nil) {
                    [msLabel removeFromSuperview];
                    msLabel = nil;
                }
                [mTableView reloadData];
            });
        });
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        NSDictionary *ret = [SendService GetShoppingCartCount];
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (ret !=nil)
            {
                if ([[ret objectForKey:@"Result"] isEqualToString:@"success"])
                {
                    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%@",[[ret objectForKey:@"Entity"] objectForKey:@"ShoppingCartCount"]] forKey:@"ShoppingCartCountKey"];
                    NSArray* viewConrolers = [self.tabBarController viewControllers];
                    ShoppingViewController* vc = [viewConrolers objectAtIndex:2];
                    vc.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@",[[ret objectForKey:@"Entity"] objectForKey:@"ShoppingCartCount"]];
                }
            }
            
        });
    });
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sweep"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yyy"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];
    
    
    UISearchBar *m_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(100, 100, 200, 41)];
    m_searchBar.delegate = self;
    m_searchBar.backgroundColor = [UIColor clearColor];
    m_searchBar.placeholder = (@"搜索所有商品");
    m_searchBar.keyboardType =  UIKeyboardTypeDefault;
    [self.navigationItem setTitleView:m_searchBar];
    
    for (UIView *view in m_searchBar.subviews) {//去除背景色

        if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
            [[view.subviews objectAtIndex:0] removeFromSuperview];
            break;
        }
    }

//    UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    CGRect frame = CGRectMake(100, 100, 200, 41);
//    [inButton setFrame:frame];
//    inButton.backgroundColor = [UIColor clearColor];
//    [inButton addTarget:self action:@selector(bInBction) forControlEvents:UIControlEventTouchUpInside];
//    [self.navigationItem setTitleView:inButton];
    
    mTableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];

    
    __weak __typeof(self) weakSelf = self;
    
    mTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf loadNewData];
    }];
// 暂时
    [mTableView.header beginRefreshing];
    
    
//    _scrollProxy = [[NJKScrollFullScreen alloc] initWithForwardTarget:self]; // UIScrollViewDelegate and UITableViewDelegate methods proxy to ViewController
//    self.mTableView.delegate = (id)_scrollProxy; // cast for surpress incompatible warnings
//    _scrollProxy.delegate = self;
    
    
}

- (void)loadNewData
{
    pageForNumber = 1;
    [self upDateTableView];
}
- (void)loadMoreData
{
    pageForNumber++;
    [self upDateTableView];
}

-(void)removeArray
{
    if (AdBigArray != nil) {
        [AdBigArray removeAllObjects];
        AdBigArray = nil;
    }
    AdBigArray = [[NSMutableArray alloc] init];
    
    if (AdMinusArray != nil) {
        [AdMinusArray removeAllObjects];
        AdMinusArray = nil;
    }
    AdMinusArray = [[NSMutableArray alloc] init];
    
    if (AdBrandArray != nil) {
        [AdBrandArray removeAllObjects];
        AdBrandArray = nil;
    }
    AdBrandArray = [[NSMutableArray alloc] init];
    
    if (AdShopThemeArray != nil) {
        [AdShopThemeArray removeAllObjects];
        AdShopThemeArray = nil;
    }
    AdShopThemeArray = [[NSMutableArray alloc] init];
    
    if (homeArray != nil) {
        [homeArray removeAllObjects];
        homeArray = nil;
    }
    homeArray = [[NSMutableArray alloc] init];
    
    if (fListArray != nil) {
        [fListArray removeAllObjects];
        fListArray = nil;
    }
    fListArray = [[NSMutableArray alloc] init];
    
    if (featuredArray != nil) {
        [featuredArray removeAllObjects];
        featuredArray = nil;
    }
    featuredArray = [[NSMutableArray alloc] init];

    if (killArray != nil) {
        [killArray removeAllObjects];
        killArray = nil;
    }
    killArray = [[NSMutableArray alloc] init];
}

-(void)upDateTableView
{
    if (pageForNumber == 1)
    {
        [self removeArray];
        
        NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
        [postDic setObject:@"AppHomeAdMinus1" forKey:@"code"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService ActiveProducts:postDic];
            dispatch_async(dispatch_get_main_queue(), ^{

                if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                {
                    for (NSDictionary *pic in [myArray objectForKey:@"Entity"])
                    {
                        [homeArray addObject:pic];
                    }
                }
                

                [mTableView.header endRefreshing];
                [mTableView reloadData];
            });
        });
#pragma mark 秒杀场次列表
        NSMutableDictionary *postDic4 = [[NSMutableDictionary alloc] init];
        [postDic4 setObject:@"AppHomeActPanicBuy" forKey:@"code"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService HomepageSecKill:postDic4];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                {
                    if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Entity"]] isEqualToString:@"<null>"])
                    {
                        for (NSDictionary *pic in [myArray objectForKey:@"Entity"])
                        {
                            [killArray addObject:pic];
                        }
                    }
                }

                NSLog(@"秒杀场次列表 %@",myArray);
                if (msLabel != nil) {
                    [msLabel removeFromSuperview];
                    msLabel = nil;
                }

                [mTableView.header endRefreshing];
                [mTableView reloadData];
            });
        });

        for (int i = 0; i < 4; i++)
        {
            NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
            if (i == 0)
                [postDic setObject:@"AppHomeAdBig" forKey:@"code"];
            else if ( i == 1)
                [postDic setObject:@"AppHomeAdMinus" forKey:@"code"];
            else if ( i == 2)
                [postDic setObject:@"AppHomeAdBrand" forKey:@"code"];
            else if ( i == 3)
                [postDic setObject:@"AppHomeAdShopTheme" forKey:@"code"];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                NSDictionary *myArray = [SendService HomepageADs:postDic];
                dispatch_async(dispatch_get_main_queue(), ^{
//                    NSLog(@"myArray %@",myArray);
                    if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                    {
                        for (NSDictionary *pic in [myArray objectForKey:@"Entity"])
                        {
                            if (i == 0)
                                [AdBigArray addObject:pic];
                            else if ( i == 1)
                                [AdMinusArray addObject:pic];
                            else if ( i == 2)
                                [AdBrandArray addObject:pic];
                            else if ( i == 3)
                                [AdShopThemeArray addObject:pic];
                        }
                    }

                    [mTableView.header endRefreshing];
                    [mTableView reloadData];
                });
            });
        }
        
        NSMutableDictionary *postDic2 = [[NSMutableDictionary alloc] init];
        [postDic2 setObject:@"AppHomeLayNewPop" forKey:@"code"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService GetWindowLayoutProductList:postDic2];
            dispatch_async(dispatch_get_main_queue(), ^{
                
                if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                {
                    if (myArray  != nil) {
                        [featuredArray addObject:[[myArray objectForKey:@"Entity"] objectForKey:@"WindowModel"]];
                    }
                    
                    for (NSDictionary *pic in [[myArray objectForKey:@"Entity"]objectForKey:@"WindowProductListModel"])
                    {
                        [featuredArray addObject:pic];
                        
                    }
                }

                [mTableView.header endRefreshing];
                [mTableView reloadData];
            });
        });
        
        NSMutableDictionary *postDic1 = [[NSMutableDictionary alloc] init];
        [postDic1 setObject:@"AppHomeLayGoodPop" forKey:@"code"];
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSDictionary *myArray = [SendService GetWindowLayoutProductList:postDic1];
            dispatch_async(dispatch_get_main_queue(), ^{
                if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"])
                {
                    for (NSDictionary *pic in [[myArray objectForKey:@"Entity"]objectForKey:@"WindowProductListModel"])
                    {
                        [fListArray addObject:pic];
                    }
                }
                
                [mTableView.header endRefreshing];
                [mTableView reloadData];
            });
        });
    }
}

-(void)handleMaxShowTimer:(NSTimer *)theTimer
{

    UIPageControl *pageControl = (UIPageControl*)[self.view viewWithTag:picTag+100];
    UIScrollView *myScroll = (UIScrollView*)[self.view viewWithTag:picTag];
    if (myScroll != nil)
    {
        
        int myCount = (int)AdBigArray.count;
        
        if (aTimerNum > myCount-1) {
            aTimerNum = 0;
        }
        else
            aTimerNum++;
        [myScroll scrollRectToVisible:CGRectMake(self.view.bounds.size.width*aTimerNum,0, self.view.bounds.size.width, adHight) animated:YES];
    }
    else
    {
        aTimerNum = 0;
        [theTimer invalidate];
        theTimer = nil;
    }
    pageControl.currentPage = aTimerNum;
}

-(void)handleMaxShoweTimer:(NSTimer *)theTimer
{
    UIPageControl *pageControl = (UIPageControl*)[self.view viewWithTag:picTag+200];
    UIScrollView *myScroll = (UIScrollView*)[self.view viewWithTag:picTag+4];
    if (myScroll != nil)
    {
        
        int myCount = (int)AdShopThemeArray.count;
        
        if (eTimerNum > myCount-1) {
            eTimerNum = 0;
        }
        else
            eTimerNum++;
        [myScroll scrollRectToVisible:CGRectMake(self.view.bounds.size.width*eTimerNum,0, self.view.bounds.size.width, adHight) animated:YES];
    }
    else
    {
        eTimerNum = 0;
        [theTimer invalidate];
        theTimer = nil;
    }
    pageControl.currentPage = eTimerNum;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int page =scrollView.bounds.origin.x/self.view.bounds.size.width;
    if (scrollView.tag == picTag)
    {
        UIPageControl *pageControl = (UIPageControl*)[self.view viewWithTag:picTag+100];
        [pageControl setCurrentPage:page] ;
    }
    else  if (scrollView.tag == picTag+4)
    {
        UIPageControl *pageControl = (UIPageControl*)[self.view viewWithTag:picTag+200];
        [pageControl setCurrentPage:page] ;
    }
}

#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section == 0)
        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
        return adHight+10+viewFrame.size.height*136/(6*98);
    else if (indexPath.section == 1)
        return viewFrame.size.height/2+20;
    else if (indexPath.section == 2)
//        return  homeArray.count*viewFrame.size.height/4+viewFrame.size.height/2+10;
       return viewFrame.size.height/4+viewFrame.size.height/2+10;
    else if (indexPath.section == 3)
        return viewFrame.size.height*.4+10;
    else if (indexPath.section == 4)
        return adHight;
    else if (indexPath.section == 5)
        return fListArray.count*viewFrame.size.height/4+10;
    return YES;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];
    
    if (indexPath.section == 0)
        return [self mCell:cell aCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 1)
        return [self mCell:cell bCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 2)
        return [self mCell:cell cCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 3)
        return [self mCell:cell dCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 4)
        return [self mCell:cell eCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 5)
        return [self mCell:cell fCTableView:aTableView cellForRowAtIndexPath:indexPath];
    
    // Configure the cell...
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell aCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    aTimerNum = 0;
    
    if ((int)AdBigArray.count > 1) {
        
        if (ADaTimer != nil) {
            [ADaTimer invalidate];
            ADaTimer = nil;
        }
        ADaTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(handleMaxShowTimer:) userInfo:nil repeats:YES];
    }

    
    UIScrollView *taScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, adHight)];
    taScrollView.backgroundColor = [UIColor whiteColor];
    [taScrollView setDelegate:self];
    [taScrollView setPagingEnabled:YES];
    taScrollView.tag = picTag+indexPath.section;
    [taScrollView setShowsHorizontalScrollIndicator:NO];
    [cell.contentView addSubview:taScrollView];
    
    [taScrollView setContentSize:CGSizeMake(self.view.bounds.size.width*AdBigArray.count,adHight)];
    
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, adHight-30, screenMySize.size.width, 30)];
    pageControl.backgroundColor = [UIColor clearColor];
    pageControl.numberOfPages = AdBigArray.count;
    pageControl.tag = picTag+100;
    pageControl.currentPage = 0;
    [cell.contentView addSubview:pageControl];
    
    
    for (int i = 0; i < AdBigArray.count; i ++)
    {
        NSMutableDictionary *dictionary = [AdBigArray objectAtIndex:i];

        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width*i,0, self.view.bounds.size.width, adHight)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictionary objectForKey:@"ImgUrl"]]]];
//        bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
//        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        [taScrollView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        inButton.tag = picTag-100+i;
        [inButton addTarget:self action:@selector(aInAction:) forControlEvents:UIControlEventTouchUpInside];
        [taScrollView addSubview:inButton];
    }
    
    for (int i = 1; i <  5; i ++)
    {
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = CGRectMake(self.view.bounds.size.width*(i-1)/4,adHight+5, viewFrame.size.height/6, viewFrame.size.height*136/(6*98));
        [inButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"circle_menu%d",i]] forState:UIControlStateNormal];
        [inButton setFrame:frame];
//        inButton.center = CGPointMake(self.view.bounds.size.width*i/5, viewFrame.size.height*5/8);
        inButton.tag = aPicTag+i;
        [inButton addTarget:self action:@selector(aInBction:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:inButton];
    }
    
    return cell;
}

-(void)gotoMSLabel
{
    NSMutableDictionary *dictionary = [killArray objectAtIndex:0];
    NSString *timeString = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"BeginCountdown"]];
    NSArray *controls = [timeString componentsSeparatedByString:@":"];
    if (controls.count>3)
    {
        for (int i = 0; i <controls.count; i++) {
            if (i == 0)
              dayInt = [[controls objectAtIndex:i] intValue];
            else if (i == 1)
                hourInt = [[controls objectAtIndex:i] intValue];
            else if (i == 2)
                minuteInt = [[controls objectAtIndex:i] intValue];
            else if (i == 3)
                secondInt = [[controls objectAtIndex:i] intValue];
        }
    }
    else
    {
        for (int i = 0; i <controls.count; i++) {
            dayInt = 0;
            if (i == 0)
                hourInt = [[controls objectAtIndex:i] intValue];
            else if (i == 1)
                minuteInt = [[controls objectAtIndex:i] intValue];
            else if (i == 2)
                secondInt = [[controls objectAtIndex:i] intValue];
        }
    }
}
-(void)KillTimer:(NSTimer *)theTimer
{
    secondInt--;
    if (secondInt == 0 && (dayInt != 0 || hourInt !=0||minuteInt!= 0 ))
    {
        minuteInt--;
        secondInt = 59;
    }
    if (minuteInt == 0 &&(dayInt != 0 || hourInt !=0 ))
    {
        hourInt --;
        minuteInt = 59;
    }
    if (hourInt == 0 && dayInt != 0)
    {
        dayInt --;
        hourInt = 59;
    }
//    NSLog(@"手机.秒杀:%d:%d:%d:%d",dayInt,hourInt,minuteInt,secondInt);
    [self msLabelTime];
   
    if (dayInt == 0 && hourInt == 0 && minuteInt == 0 && secondInt == 0 ) {

        msLabel.text = [NSString stringWithFormat:@"00   00    00"];
        [theTimer invalidate];
        theTimer = nil;
    }
}

-(void)msLabelTime
{
    NSString *h = [NSString stringWithFormat:@"%d",hourInt+dayInt*24];
    NSString *m = [NSString stringWithFormat:@"%d",minuteInt];
    NSString *s = [NSString stringWithFormat:@"%d",secondInt];
    if (hourInt < 10) {
        h = [NSString stringWithFormat:@"0%d",hourInt];
    }
    if (minuteInt < 10) {
        m = [NSString stringWithFormat:@"0%d",minuteInt];
    }
    if (secondInt < 10) {
        s = [NSString stringWithFormat:@"0%d",secondInt];
    }
    msLabel.text = [NSString stringWithFormat:@"%@   %@    %@",h,m,s];
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell bCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    killArray
    if (killArray.count>0)
    {
        NSMutableDictionary *dictionary = [killArray objectAtIndex:0];
        UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10,3, self.view.bounds.size.width-20, viewFrame.size.height/4+20-5)];
        bgdView.backgroundColor = [UIColor grayColor];
        bgdView.layer.cornerRadius = 5.0f;
        [cell.contentView addSubview:bgdView];
        
        UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width-21, viewFrame.size.height/4+20-6)];
        bView.backgroundColor = [UIColor whiteColor];
        bView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bView];

        UIImageView *killImageView = [[UIImageView alloc] initWithFrame:CGRectMake(11,3, 400/3, 53/3)];
        [killImageView setImage:[UIImage imageNamed:@"killTime1"]];
        [bgdView addSubview:killImageView];
        
        if (msLabel == nil)
        {
            [self gotoMSLabel];
            
            msLabel = [[UILabel alloc] initWithFrame:CGRectMake(70,2, self.view.bounds.size.width-20, 20)];
            msLabel.textAlignment = 0;
            msLabel.font = [UIFont fontWithName:@"Arial" size:labelSize-2];
            msLabel.textColor = [UIColor blackColor];
            [bgdView addSubview:msLabel];
            [self msLabelTime];
            if (KillTimer != nil) {
                [KillTimer invalidate];
                KillTimer = nil;
            }
           KillTimer =  [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(KillTimer:) userInfo:nil repeats:YES];
        }
        else
        {
            [bgdView addSubview:msLabel];
        }
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,20.5, self.view.bounds.size.width-21, viewFrame.size.height/4-6)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictionary objectForKey:@"ImageUrl"]]]];
//        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        bgImageView.backgroundColor = [UIColor clearColor];
        bgImageView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        [inButton addTarget:self action:@selector(bInAction) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:inButton];
    }
    
    for (int i = 0; i < AdMinusArray.count; i ++)
    {
        if (i > 1)
            return cell;
         NSMutableDictionary *dictionary = [AdMinusArray objectAtIndex:i];
        
        UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10+i*(self.view.bounds.size.width-20-self.view.bounds.size.width*2.2/5),25+viewFrame.size.height/4, self.view.bounds.size.width*2.2/5, viewFrame.size.height/4-10)];
        bgdView.backgroundColor = [UIColor grayColor];
        bgdView.layer.cornerRadius = 5.0f;
        [cell.contentView addSubview:bgdView];
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width*2.2/5-1, viewFrame.size.height/4-11)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictionary objectForKey:@"ImgUrl"]]]];
//        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        bgImageView.backgroundColor = [UIColor clearColor];
        bgImageView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        inButton.tag = picTag-200+i;
        [inButton addTarget:self action:@selector(bInAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgdView addSubview:inButton];
    }
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell cCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    for (int i = 0; i < homeArray.count; i ++)
//    {
//        NSMutableDictionary *dictionary = [homeArray objectAtIndex:i];
//        
//        UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10,5+i*viewFrame.size.height/4, self.view.bounds.size.width-20, viewFrame.size.height/4-5)];
//        bgdView.backgroundColor = [UIColor grayColor];
//        bgdView.layer.cornerRadius = 5.0f;
//        [cell.contentView addSubview:bgdView];
//        
//        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width-21, viewFrame.size.height/4-6)];
//        bgView.backgroundColor = [UIColor whiteColor];
//        bgView.layer.cornerRadius = 5.0f;
//        [bgdView addSubview:bgView];
//
//        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width/2-10, viewFrame.size.height/4-6)];
//        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"DefaultPictureModel" ] objectForKey:@"ImageUrl"]]]];
//        bgImageView.clipsToBounds  = YES;
//        bgImageView.backgroundColor = [UIColor clearColor];
//        bgImageView.layer.cornerRadius = 5.0f;
//        [bgdView addSubview:bgImageView];
//
//        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2,5, self.view.bounds.size.width/2-20, viewFrame.size.height*3/16)];
//        titleLabel.text = [NSString stringWithFormat:@"%@",[dictionary objectForKey:@"Name"]];
//        titleLabel.textAlignment = 0;
//        titleLabel.numberOfLines = 3;
//        titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize-2];
//        titleLabel.textColor = [UIColor blackColor];
//        [bgdView addSubview:titleLabel];
//        
//        UILabel *title1Label = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2,viewFrame.size.height*3/16, self.view.bounds.size.width/2-20, viewFrame.size.height/16-10)];
//        title1Label.text = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"ProductPrice"] objectForKey:@"Price"]];
//        title1Label.textAlignment = 0;
//        title1Label.font = [UIFont fontWithName:@"Arial" size:labelSize+1];
//        title1Label.backgroundColor = [UIColor clearColor];
//        title1Label.textColor = [UIColor redColor];
//        [bgdView addSubview:title1Label];
//        
//        
//        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        CGRect frame = bgView.frame;
//        [inButton setFrame:frame];
//        inButton.tag =cTag + i;
//        [inButton addTarget:self action:@selector(cInAction:) forControlEvents:UIControlEventTouchUpInside];
//        [bgdView addSubview:inButton];
//        
//        
//    }
    int  addds = 1;
//    homeArray.count 替换 addds
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,5, self.view.bounds.size.width-20, viewFrame.size.height/4-6)];
    [bgImageView  setImage:[UIImage imageNamed:@"tuangou"]];
    bgImageView.clipsToBounds  = YES;
    bgImageView.backgroundColor = [UIColor clearColor];
    bgImageView.layer.cornerRadius = 5.0f;
    [cell.contentView addSubview:bgImageView];

    
    UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10,5+addds*viewFrame.size.height/4, self.view.bounds.size.width-20, viewFrame.size.height/2)];
    bgdView.backgroundColor = [UIColor grayColor];
    bgdView.layer.cornerRadius = 5.0f;
    [cell.contentView addSubview:bgdView];
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width-21, viewFrame.size.height/2-1)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 5.0f;
    [bgdView addSubview:bgView];
    
    UIView *bg3View = [[UIView alloc] initWithFrame:CGRectMake((self.view.bounds.size.width-21)/2+20,viewFrame.size.height/4, .5, viewFrame.size.height/4-1)];
    bg3View.backgroundColor = [UIColor grayColor];
    [bgdView addSubview:bg3View];
    
    UIView *bg2View = [[UIView alloc] initWithFrame:CGRectMake(0,viewFrame.size.height/4, self.view.bounds.size.width-21, .5)];
    bg2View.backgroundColor = [UIColor grayColor];
    [bgdView addSubview:bg2View];
    
    UIView *bg1View = [[UIView alloc] initWithFrame:CGRectMake((self.view.bounds.size.width-20)/3+.5,.5, .5, viewFrame.size.height/4-1)];
    bg1View.backgroundColor = [UIColor grayColor];
    [bgdView addSubview:bg1View];
    

    if (featuredArray.count>0)
    {
        NSMutableDictionary *dictionary = [featuredArray objectAtIndex:0];
        UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,.5, (self.view.bounds.size.width-20)/3, 35*(self.view.bounds.size.width-20)/(3*135))];
        [bg1ImageView setImage:[UIImage imageNamed:@"xptj"]];
        [bgdView addSubview:bg1ImageView];
        
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,35*(self.view.bounds.size.width-20)/(3*135)+.5, (self.view.bounds.size.width-20)/3, viewFrame.size.height/4-35*(self.view.bounds.size.width-20)/(3*135)-1)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[dictionary objectForKey:@"BigLogoPictureUrl"]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        [bgdView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        inButton.tag = cTag+100;
        [inButton addTarget:self action:@selector(cInTwoAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgdView addSubview:inButton];
    }
    
    for (int i = 0; i < featuredArray.count; i ++)
    {
        if (i>2)
            return cell;
        NSMutableDictionary *dictionary = [featuredArray objectAtIndex:i+1];
        
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 0, 0)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"BigImageUrl"]]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        [bgdView addSubview:bgImageView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 0, 0)];
        titleLabel.text = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"ProductName"]];
        titleLabel.textAlignment = 0;
        titleLabel.numberOfLines = 3;
        titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize-2];
        titleLabel.textColor = [UIColor blackColor];
        [bgdView addSubview:titleLabel];
        
        UILabel *title1Label = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 0, 0)];
        title1Label.text = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"Price"]];
        title1Label.textAlignment = 0;
        title1Label.font = [UIFont fontWithName:@"Arial" size:labelSize+1];
        title1Label.backgroundColor = [UIColor clearColor];
        title1Label.textColor = [UIColor redColor];
        [bgdView addSubview:title1Label];
        
        if (i == 0)
        {
            bgImageView.frame = CGRectMake((self.view.bounds.size.width-20)/3+1, 1,self.view.bounds.size.width/4-5 , viewFrame.size.height/4-3);
            bgImageView.center = CGPointMake((self.view.bounds.size.width-20)/3+(self.view.bounds.size.width/4-5)/2+2, viewFrame.size.height/8+1);
            titleLabel.frame = CGRectMake(bg1View.frame.origin.x+self.view.bounds.size.width/4, 5,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-5,viewFrame.size.height*3/16);
            
            title1Label.frame = CGRectMake(bg1View.frame.origin.x+self.view.bounds.size.width/4, viewFrame.size.height*3/16,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-5,viewFrame.size.height/16);
        }
        else if (i == 1)
        {
            bgImageView.frame = CGRectMake(.5, 6+viewFrame.size.height/4,self.view.bounds.size.width/4-5 , self.view.bounds.size.width/4-5);
            
            bgImageView.center = CGPointMake((self.view.bounds.size.width/4-5)/2+1, viewFrame.size.height*3/8);
            titleLabel.frame = CGRectMake(.5+self.view.bounds.size.width/4-5, .5+viewFrame.size.height/4,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-25,viewFrame.size.height*3/16);
            
            title1Label.frame = CGRectMake(.5+self.view.bounds.size.width/4-5, viewFrame.size.height*3/16+viewFrame.size.height/4,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-25,viewFrame.size.height/16);
        }
        else if (i == 2)
        {
            bgImageView.frame = CGRectMake(self.view.bounds.size.width/2+10.5, 6+viewFrame.size.height/4,self.view.bounds.size.width/4-15 , self.view.bounds.size.width/4-5);
            bgImageView.center = CGPointMake(self.view.bounds.size.width/2+10.5+(self.view.bounds.size.width/4-15)/2, viewFrame.size.height*3/8);
            titleLabel.frame = CGRectMake(self.view.bounds.size.width/2+self.view.bounds.size.width/4, .5+viewFrame.size.height/4,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-60,viewFrame.size.height*3/16);
            
            title1Label.frame = CGRectMake(self.view.bounds.size.width/2+self.view.bounds.size.width/4, viewFrame.size.height*3/16+viewFrame.size.height/4,self.view.bounds.size.width-20-bg1View.frame.origin.x-self.view.bounds.size.width/4-60,viewFrame.size.height/16);
        }
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        if (i == 0)
            inButton.frame =CGRectMake((self.view.bounds.size.width-20)/3+.5,.5, self.view.bounds.size.width-(self.view.bounds.size.width-20)/3, viewFrame.size.height/4-1);
        else if (i == 1)
            inButton.frame = CGRectMake(0,viewFrame.size.height/4, self.view.bounds.size.width-21, viewFrame.size.height/4);
        else if (i == 2)
            inButton.frame =CGRectMake((self.view.bounds.size.width-21)/2+20,viewFrame.size.height/4, (self.view.bounds.size.width-21)/2, viewFrame.size.height/4-1);
        inButton.tag = cTag+i+100+1;
        [inButton addTarget:self action:@selector(cInTwoAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgdView addSubview:inButton];

    }
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell dCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10,5, self.view.bounds.size.width-20, viewFrame.size.height*.4)];
    bgdView.backgroundColor = [UIColor grayColor];
    bgdView.layer.cornerRadius = 5.0f;
    [cell.contentView addSubview:bgdView];
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width-21, viewFrame.size.height*.4-1)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 5.0f;
    [bgdView addSubview:bgView];
    
    UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,.5, 135*3/4, 35*3/4)];
    [bg1ImageView setImage:[UIImage imageNamed:@"pptm"]];
    [bgdView addSubview:bg1ImageView];
    
    for (int i = 0; i < AdBrandArray.count; i++) {
        if (i>3) {
            return cell;
        }
        NSMutableDictionary *dictionary = [AdBrandArray objectAtIndex:i];
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5+i*(self.view.bounds.size.width-20)/4,35*3/4+.5, (self.view.bounds.size.width-20)/4-1, viewFrame.size.height*.4-35*3/4-1)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictionary objectForKey:@"ImgUrl"]]]];
        bgImageView.clipsToBounds  = YES;
        bgImageView.backgroundColor = [UIColor clearColor];
        bgImageView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        inButton.tag = picTag-400+i;
        [inButton addTarget:self action:@selector(dInAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgdView addSubview:inButton];
    }
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell eCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor clearColor];
    
    
    eTimerNum = 0;
    if ((int)AdShopThemeArray.count > 1) {
        
        if (ADeTimer != nil) {
            [ADeTimer invalidate];
            ADeTimer = nil;
        }
        ADeTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(handleMaxShoweTimer:) userInfo:nil repeats:YES];
    }
    
    UIScrollView *taScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, adHight)];
    taScrollView.backgroundColor = [UIColor clearColor];
    [taScrollView setDelegate:self];
    [taScrollView setPagingEnabled:YES];
    taScrollView.tag = picTag+indexPath.section;
    [taScrollView setShowsHorizontalScrollIndicator:NO];
    [cell.contentView addSubview:taScrollView];
    
    [taScrollView setContentSize:CGSizeMake(self.view.bounds.size.width*AdShopThemeArray.count,adHight)];
    
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, adHight-30, screenMySize.size.width, 30)];
    pageControl.backgroundColor = [UIColor clearColor];
    pageControl.numberOfPages = AdShopThemeArray.count;
    pageControl.tag = picTag+200;
    pageControl.currentPage = 0;
    [cell.contentView addSubview:pageControl];
    
    for (int i = 0; i < AdShopThemeArray.count; i ++)
    {
        NSMutableDictionary *dictionary = [AdShopThemeArray objectAtIndex:i];
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width*i,0, self.view.bounds.size.width, adHight)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictionary objectForKey:@"ImgUrl"]]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFill;
        bgImageView.clipsToBounds  = YES;
        [taScrollView addSubview:bgImageView];
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgImageView.frame;
        [inButton setFrame:frame];
        inButton.tag = picTag-500+i;
        [inButton addTarget:self action:@selector(eInAction:) forControlEvents:UIControlEventTouchUpInside];
        [taScrollView addSubview:inButton];
    }
    
    return cell;
}


- (UITableViewCell *)mCell:(UITableViewCell*)cell fCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    for (int i = 0; i < fListArray.count; i ++)
    {
        NSMutableDictionary *dictionary = [fListArray objectAtIndex:i];
        
        UIView *bgdView = [[UIView alloc] initWithFrame:CGRectMake(10,5+i*viewFrame.size.height/4, self.view.bounds.size.width-20, viewFrame.size.height/4-5)];
        bgdView.backgroundColor = [UIColor grayColor];
        bgdView.layer.cornerRadius = 5.0f;
        [cell.contentView addSubview:bgdView];
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width-21, viewFrame.size.height/4-6)];
        bgView.backgroundColor = [UIColor whiteColor];
        bgView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bgView];
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(.5,.5, self.view.bounds.size.width/2-10, viewFrame.size.height/4-6)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"BigImageUrl"]]]];
        bgImageView.clipsToBounds  = YES;
        bgImageView.backgroundColor = [UIColor clearColor];
        bgImageView.layer.cornerRadius = 5.0f;
        [bgdView addSubview:bgImageView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2,5, self.view.bounds.size.width/2-20, viewFrame.size.height*3/16)];
        titleLabel.text = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"ProductName"]];
        titleLabel.textAlignment = 0;
        titleLabel.numberOfLines = 3;
        titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize-2];
        titleLabel.textColor = [UIColor blackColor];
        [bgdView addSubview:titleLabel];
        
        UILabel *title1Label = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2,viewFrame.size.height*3/16, self.view.bounds.size.width/2-20, viewFrame.size.height/16-10)];
        title1Label.text = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"Product"]objectForKey:@"Price"]];
        title1Label.textAlignment = 0;
        title1Label.font = [UIFont fontWithName:@"Arial" size:labelSize+1];
        title1Label.backgroundColor = [UIColor clearColor];
        title1Label.textColor = [UIColor redColor];
        [bgdView addSubview:title1Label];
        
        
        UIButton *inButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect frame = bgView.frame;
        [inButton setFrame:frame];
        inButton.tag = fTag+i;
        [inButton addTarget:self action:@selector(cInfAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgdView addSubview:inButton];
        
        
    }
    return cell;
}

-(void)AdWebView:(NSString*)urlValue
{
    ADWebViewController *details = [[ADWebViewController alloc] init];
    details.DestionValue = [NSString stringWithFormat:@"%@",urlValue];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

-(void)setDic:(NSDictionary*)dic
{
    NSString *typeString = [NSString stringWithFormat:@"%@",[dic objectForKey:@"DestionType"]];
    if ([typeString isEqualToString:@"1"])
    {
        [self AdWebView:[NSString stringWithFormat:@"%@",[dic objectForKey:@"DestionValue"]]];
    }
    else if ([typeString isEqualToString:@"2"] || [typeString isEqualToString:@"3"])
    {
        [self ADTableView:[NSString stringWithFormat:@"%@",[dic objectForKey:@"DestionValue"]] setType:typeString];
    }
    else if ([typeString isEqualToString:@"4"])
    {
        NSLog(@"dic %@",dic);
        ADFourViewController *details = [[ADFourViewController alloc] init];
        details.stringId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"DestionValue"]];
        details.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:details animated:YES];
        
    }
}
-(void)ADTableView:(NSString*)tionValue setType:(NSString*)tionType
{
    ADTableViewController *details = [[ADTableViewController alloc] init];
    details.DestionValue = [NSString stringWithFormat:@"%@",tionValue];
    details.DestionType = [NSString stringWithFormat:@"%@",tionType];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

#pragma mark a广告图片
-(void)aInAction:(id)sender
{
    int type = ((UIButton*)sender).tag+100-picTag;
    [self setDic:[AdBigArray objectAtIndex:type]];

}
#pragma mark a图片类别
-(void)aInBction:(id)sender
{
    
}
#pragma mark 秒杀
-(void)bInAction
{
    KillListViewController *details = [[KillListViewController alloc] init];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}
#pragma mark b广告图片
-(void)bInAction:(id)sender
{
    int type = ((UIButton*)sender).tag+200-picTag;
    [self setDic:[AdMinusArray objectAtIndex:type]];
}
#pragma mark d广告图片
-(void)dInAction:(id)sender
{
    int type = ((UIButton*)sender).tag+400-picTag;
    [self setDic:[AdBrandArray objectAtIndex:type]];
}

#pragma mark e广告图片
-(void)eInAction:(id)sender
{
    int type = ((UIButton*)sender).tag+500-picTag;
    [self setDic:[AdShopThemeArray objectAtIndex:type]];
}
#pragma mark c一列
-(void)cInAction:(id)sender
{
    int type = ((UIButton*)sender).tag-cTag;
    if (homeArray.count<= type) {
        return;
    }
    NSMutableDictionary *dictionary = [homeArray objectAtIndex:type];
    [self setNSMutableDictionary:dictionary];
    
}
#pragma mark c三列
-(void)cInTwoAction:(id)sender
{
    int type = ((UIButton*)sender).tag-cTag-100;
    if (featuredArray.count<= type) {
        return;
    }
    GoodsDetailsViewController *details = [[GoodsDetailsViewController alloc] init];
    if (type == 0) {
        details.productId = [NSString stringWithFormat:@"%@",[[featuredArray objectAtIndex:type] objectForKey:@"Id"]];
    }
    else
    details.productId = [NSString stringWithFormat:@"%@",[[[featuredArray objectAtIndex:type] objectForKey:@"Product"] objectForKey:@"ProductId"]];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
    
}

#pragma mark f列表
-(void)cInfAction:(id)sender
{
    int type = ((UIButton*)sender).tag-fTag;
    if (fListArray.count<= type) {
        return;
    }
    GoodsDetailsViewController *details = [[GoodsDetailsViewController alloc] init];
    details.productId = [NSString stringWithFormat:@"%@",[[[fListArray objectAtIndex:type] objectForKey:@"Product"] objectForKey:@"ProductId"]];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

#pragma mark 详情界面跳转
-(void)setNSMutableDictionary:(NSMutableDictionary*)dictionary
{
    GoodsDetailsViewController *details = [[GoodsDetailsViewController alloc] init];
    details.productId = [NSString stringWithFormat:@"%@",[[dictionary objectForKey:@"ReviewOverviewModel"] objectForKey:@"ProductId"]];
    details.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:details animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
